from langchain_community.vectorstores.elastic_vector_search import ElasticVectorSearch
from langchain_zhipu import ChatZhipuAI, ZhipuAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import TextLoader
from elasticsearch import Elasticsearch

embeddings = ZhipuAIEmbeddings(api_key="d3708ee404327e207b2f003775e06908.X3dgRCxbkyDfEIbh")


# 加载数据

loader = TextLoader("index.md")
localText = loader.load()

text_splitter = RecursiveCharacterTextSplitter()
document = text_splitter.split_documents(localText)
document_store = ElasticVectorSearch(
    elasticsearch_url="http://localhost:9200",
    index_name="test_index",
    embedding=embeddings
)
document_store.add_documents(documents=document)
